<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();//获得当前的项目根目录路径赋值给path
%>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>校园失物招领系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/login.css" media="all">

</head>
<body class="layui-layout-body">

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;background: none no-repeat">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>校园失物招领系统</h2>
            <p>注册窗口</p>
        </div>
        <span class="msg" style="color:red;">${requestScope.msg}</span>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">

            <form  action="${pageContext.request.contextPath}/user/add" method="post">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="stuno"></label>
                    <input type="text" name="stuno" id="stuno"  required  placeholder="学号" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="nick_name"></label>
                    <input type="text" name="nick_name" id="nick_name" required  placeholder="昵称" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="pwd"></label>
                    <input type="password" name="pwd" id="pwd" lay-verify="required" placeholder="密码" class="layui-input">
                </div>

                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="phone"></label>
                    <input type="password" name="phone" id="phone" required lay-verify="phone" placeholder="手机号" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-circle" for="province"></label>
                    <input type="text" name="province" id="province"  placeholder="省份" class="layui-input">
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">性&emsp;&emsp;别</label>
                    <div class="layui-input-block">
                        <select name="sex" id="sex" >
                            <option value="1">男</option>
                            <option value="2" selected>女</option>
                        </select>
                    </div>
                </div>




                <div class="layui-form-item">
                    <label class="layui-form-label">年&emsp;&emsp;级</label>
                    <div class="layui-input-block">
                        <select name="grade" lay-verify="required" lay-filter="aihao">
                            <option value="大一" selected>大一</option>
                            <option value="大二" >大二</option>
                            <option value="大三" >大三</option>
                            <option value="大四" >大四</option>

                        </select>
                    </div>

                </div>



                <div class="layui-form-item">

                    <div class="layui-upload-drag" id="headImg">
                        <img class="layui-upload-img headImage" src="<%=path%>/static/images/upload.png" id="demo1" style="width:100px;height:100%">
                        <p id="demoText"></p>
                        <p>点击上传图片</p>
                    </div>

                    <input type="hidden" name="photo" id="photo"  />
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" id="login" type="submit">立即注册</button>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-normal layui-btn-fluid" onclick="location.href='/toLogin'"  type="button">返回登录</button>
                </div>
            </form>
        </div>



    </div>

</div>




<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.use(['layer', 'form','element','upload'], function(){
        var layer = layui.layer,
            element=layui.element,
            form = layui.form,
            upload=layui.upload,
            $ = layui.$;

        $("#login").click(function () {
            var stunoText = $("#stuno").val();
            if (stunoText == "") {
                $("span.msg").text("用户名不许为空！");
                layer.alert('酷毙了', {icon: 1});


                return false;
            }

        });



        var uploadInst = upload.render({

            elem: '#headImg'
            , url: '${pageContext.request.contextPath}/utils/add.action'
            ,method: 'post'
            , size: 5000

            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                //打印后台传回的地址: 把地址放入一个隐藏的input中, 和表单一起提交到后台, 此处略..
                /*   console.log(res.data.src);*/
                /* window.parent.uploadHeadImage(res.data.src); */
                console.log(res.data.src);
                $("#photo").val(res.data.src);
                var demoText = $('#demoText');
                demoText.html('<span style="color: #8f8f8f;">上传成功!!!</span>');
            }
            , error: function (res) {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }

        });
        form.render();


    });
</script>


</body>
</html>


